{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Combine Mulitple Glyphs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:bokeh.core.state:Session output file 'Output//4_2-multiple.html' already exists, will be overwritten.\n"
     ]
    }
   ],
   "source": [
    "from bokeh.plotting import figure,output_file,show\n",
    "\n",
    "x0=[1,2,3,4,5]\n",
    "y0=[6,7,8,7,3]\n",
    "\n",
    "output_file(\"Output//4_2-multiple.html\")\n",
    "p=figure(plot_width=400,plot_height=400)\n",
    "\n",
    "#add both a line and circles on the same plot\n",
    "p.line(x0,y0,line_width=2)\n",
    "p.circle(x0,y0,fill_color=\"white\",size=8)\n",
    "p.text(x=x0, y=y0, text=[\"(%d, %d)\" % (i,j) for (i, j) in zip(x0, y0)],\n",
    "       text_baseline=\"bottom\", text_align=\"center\")\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Setting Ranges 设置范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:bokeh.core.state:Session output file 'Output//4_2-setRange.html' already exists, will be overwritten.\n"
     ]
    }
   ],
   "source": [
    "#use Range1d t osetup x_range and y_range\n",
    "from bokeh.plotting import figure,output_file,show\n",
    "from bokeh.models import Range1d\n",
    "\n",
    "output_file(\"Output//4_2-setRange.html\")\n",
    "p=figure(plot_width=400,plot_height=400,x_range=(0,20))\n",
    "#set a range using a Range1d\n",
    "p.y_range=Range1d(1,15,bounds=(0,None))\n",
    "p.circle(x=[1,2,3,4,5],y=[2,5,8,2,7],size=10)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Categorical Axes 轴坐标值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:bokeh.core.state:Session output file 'Output//4_2-categorical.html' already exists, will be overwritten.\n"
     ]
    }
   ],
   "source": [
    "from bokeh.plotting import figure,output_file,show\n",
    "\n",
    "output_file(\"Output//4_2-categorical.html\")\n",
    "factors=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"]\n",
    "x=[50,40,65,10,25,37,80,60]\n",
    "p=figure(y_range=factors)\n",
    "p.circle(x,factors,size=15,fill_color=\"orange\",line_color=\"green\",\n",
    "        line_width=3)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Datetime Axes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:bokeh.core.state:Session output file 'Output//4_2-datetime.html' already exists, will be overwritten.\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from bokeh.plotting import figure,output_file,show\n",
    "from bokeh.sampledata.stocks import AAPL\n",
    "\n",
    "output_file(\"Output//4_2-datetime.html\")\n",
    "df=pd.DataFrame(AAPL)\n",
    "df['date']=pd.to_datetime(df['date'])\n",
    "df.head()\n",
    "#create a new plot iwth datetime axis type\n",
    "#x_range的数据类型需要和数据源一致\n",
    "p=figure(plot_width=800,plot_height=250,x_axis_type=\"datetime\",\n",
    "         x_range=(pd.to_datetime('2008-1-1'),pd.to_datetime('2012-12-31')))\n",
    "p.line(x=df['date'],y=df['close'],color='navy',alpha=0.5)\n",
    "p.line(x=df['date'],y=df['low'],color='orange',alpha=0.5)\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Log Scale Axes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, output_file, show\n",
    "\n",
    "x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]\n",
    "y = [10**xx for xx in x]\n",
    "\n",
    "output_file(\"Output//4_2-log.html\")\n",
    "\n",
    "# create a new plot with a log axis type\n",
    "p = figure(plot_width=400, plot_height=400, y_axis_type=\"log\")\n",
    "\n",
    "p.line(x, y, line_width=2)\n",
    "p.circle(x, y, fill_color=\"white\", size=8)\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Twin Axes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import pi, arange, sin, linspace\n",
    "\n",
    "from bokeh.plotting import output_file, figure, show\n",
    "from bokeh.models import LinearAxis, Range1d\n",
    "\n",
    "x = arange(-2*pi, 2*pi, 0.1)\n",
    "y = sin(x)\n",
    "y2 = linspace(0, 100, len(y))\n",
    "\n",
    "output_file(\"Output//4_2-twin_axis.html\")\n",
    "\n",
    "p = figure(x_range=(-6.5, 6.5), y_range=(-1.1, 1.1))\n",
    "\n",
    "p.circle(x, y, color=\"red\")\n",
    "\n",
    "p.extra_y_ranges = {\"foo\": Range1d(start=0, end=100)}\n",
    "p.circle(x, y2, color=\"blue\", y_range_name=\"foo\")\n",
    "p.add_layout(LinearAxis(y_range_name=\"foo\"), 'left')\n",
    "\n",
    "show(p)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
